home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 428_02 / libsrc / wpane.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-13  |  3.2 KB  |  156 lines

  1. /*
  2. ** wpane.c
  3. **
  4. ** Pictor, Version 1.51, Copyright (c) 1992-94 SoftCircuits
  5. ** Redistributed by permission.
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include "pictor.h"
  11.  
  12.  
  13. /*
  14. ** Selects the active window pane.
  15. */
  16. int setwpane(int handle)
  17. {
  18.     if(_PL_winhead == NULL || handle < 0 || handle >= _PL_winhead->numpanes)
  19.         return(FALSE);
  20.  
  21.     _PL_winhead->currpane = handle;
  22.     if(_PL_winhead->style & WO_TEXTCURSOR)
  23.         wsynccurs();
  24.  
  25.     return(TRUE);
  26.  
  27. } /* setwpane */
  28.  
  29. static char split_top[][2] = {
  30.     { '\xCD','\xD1' },
  31.     { '\xC4','\xC2' },
  32.     { '\xC1','\xC5' },
  33.     { '\x00',' ' }
  34. };
  35.  
  36. static char split_bottom[][2] = {
  37.     { '\xCD','\xCF' },
  38.     { '\xC4','\xC1' },
  39.     { '\xC2','\xC5' },
  40.     { '\x00',' '}
  41. };
  42.  
  43. static char split_left[][2] = {
  44.     { '\xBA','\xC7' },
  45.     { '\xB3','\xC3' },
  46.     { '\xB4','\xC5' },
  47.     { '\x00',' ' }
  48. };
  49.  
  50. static char split_right[][2] = {
  51.     { '\xBA','\xB6' },
  52.     { '\xB3','\xB4' },
  53.     { '\xC3','\xC5' },
  54.     { '\x00',' ' }
  55. };
  56.  
  57. char lookup_char(char (*table)[2])
  58. {
  59.     int i;
  60.     char c;
  61.  
  62.     c = (char)(vgetca() & 0xFF);
  63.  
  64.     _PL_offset -= 2;
  65.  
  66.     for(i = 0;table[i][0] != '\x00';i++) {
  67.         if(c == table[i][0])
  68.             return(table[i][1]);
  69.     }
  70.     return(table[i][1]);
  71.  
  72. } /* lookup_char */
  73.  
  74. /*
  75. ** Divides the active window pane into 2 panes. NOTE: windows
  76. ** with the WO_STATICMEM attribute cannot have multiple panes.
  77. ** Returns a handle to the new pane, or 0 if the pane could not
  78. ** be created.
  79. */
  80. int wpane(int direction,int split)
  81. {
  82.     PANESTRUCT *oldpane,*newpane;
  83.     WINDOW *win;
  84.     int i;
  85.  
  86.     win = _PL_winhead;
  87.  
  88.     if(win == NULL || win->style & WO_STATICMEM)
  89.         return(0);
  90.  
  91.  
  92.     if(direction == WP_HORIZONTAL) {
  93.         if(split < 3 || split > getwrows())
  94.             return(0);
  95.     }
  96.     else if(direction == WP_VERTICAL) {
  97.         if(split < 3 || split > getwcols())
  98.             return(0);
  99.     }
  100.     else return(0);
  101.  
  102.     win = realloc(_PL_winhead,
  103.         sizeof(WINDOW) + (sizeof(PANESTRUCT) * _PL_winhead->numpanes));
  104.  
  105.     if(win == NULL)
  106.         return(0);
  107.     else
  108.         _PL_winhead = win;
  109.  
  110.     oldpane = (win->panes + win->currpane);
  111.     newpane = (win->panes + win->numpanes);
  112.     win->numpanes++;
  113.  
  114.     vcolor(win->color);
  115.  
  116.     if(direction == WP_HORIZONTAL) {
  117.         newpane->left = oldpane->left;
  118.         newpane->width = oldpane->width;
  119.         newpane->color = oldpane->color;
  120.         newpane->top = (oldpane->top + (split - 1));
  121.         newpane->height = (oldpane->height - (split - 1));
  122.         oldpane->height = split;
  123.  
  124.         setvpos(newpane->top,newpane->left);
  125.         vputc(lookup_char(split_left));
  126.         vrepc('\xC4',newpane->width - 2);
  127.         vputc(lookup_char(split_right));
  128.     }
  129.     else {   /* WP_VERTICAL */
  130.         newpane->top = oldpane->top;
  131.         newpane->height = oldpane->height;
  132.         newpane->color = oldpane->color;
  133.         newpane->left = (oldpane->left + (split - 1));
  134.         newpane->width = (oldpane->width - (split - 1));
  135.         oldpane->width = split;
  136.  
  137.         setvpos(newpane->top,newpane->left);
  138.         vputc(lookup_char(split_top));
  139.         for(i = 0;i < newpane->height - 2;i++) {
  140.             setvpos(newpane->top + 1 + i,newpane->left);
  141.             vputc('\xB3');
  142.         }
  143.         setvpos(newpane->top + 1 + i,newpane->left);
  144.         vputc(lookup_char(split_bottom));
  145.     }
  146.  
  147.     /* clear new pane */
  148.     i = win->currpane;
  149.     win->currpane = (win->numpanes - 1);
  150.     wclear();
  151.     win->currpane = i;
  152.  
  153.     return(win->numpanes - 1);
  154.  
  155. } /* wpane */
  156.